package com.jdew.thkj.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jdew.thkj.R;
import com.jdew.thkj.bean.FansBean;
import com.jdew.thkj.view.CircleImageView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yangzai on 2018/4/20 0020.
 */

public class MyFansAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private List<FansBean.DataBean> dataList;
    private LayoutInflater layoutInflater;
    private Context context;
    private View itemView;

    public MyFansAdapter(Context context, List<FansBean.DataBean> dataList) {
        this.context=context;
        this.dataList = dataList;
        layoutInflater = LayoutInflater.from(context);
    }
    public void setDataList(List<FansBean.DataBean> dataList){
        this.dataList=dataList;
        notifyDataSetChanged();
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        itemView = layoutInflater.inflate(R.layout.fans_item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myviewHolder=(MyViewHolder)holder;
        myviewHolder.BindView(holder,position);
        myviewHolder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.logo)
        CircleImageView logo;
        @Bind(R.id.phone)
        TextView phone;
        @Bind(R.id.date)
        TextView date;
        @Bind(R.id.type)
        TextView type;
        @Bind(R.id.type1)
        TextView type1;
        @Bind(R.id.type2)
        TextView type2;
        @Bind(R.id.line)
        View line;
        @Bind(R.id.line1)
        View line1;
        @Bind(R.id.view)
        LinearLayout view;
        @Bind(R.id.view1)
        LinearLayout view1;
        @Bind(R.id.view2)
        LinearLayout view2;
        MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
        public void BindView(RecyclerView.ViewHolder holder, int position){
             if(null!=dataList.get(position).getUserName()){
                 ((MyViewHolder) holder).phone.setText(dataList.get(position).getUserName()+" "+dataList.get(position).getUserPhone());
             }else{
                 ((MyViewHolder) holder).phone.setText(dataList.get(position).getUserPhone());
             }
            ((MyViewHolder) holder).date.setText(dataList.get(position).getUserZcTime());
            if(dataList.get(position).getSpareTwo().equals("0")){
                type.setText(dataList.get(position).getUserCode()+"人");
                type1.setText(dataList.get(position).getUserPwd()+"人");
                type2.setText(dataList.get(position).getUserNewPwd()+"人");
            }else if(dataList.get(position).getSpareTwo().equals("2")){
                view.setVisibility(View.GONE);
                type1.setText(dataList.get(position).getUserPwd()+"人");
                type2.setText(dataList.get(position).getUserNewPwd()+"人");
            }else{
                view.setVisibility(View.GONE);
                view1.setVisibility(View.GONE);
                view2.setVisibility(View.GONE);
                line1.setVisibility(View.GONE);
                line.setVisibility(View.GONE);
            }
            if(null!=dataList.get(position).getUserImgUrl() && !dataList.get(position).getUserImgUrl().equals("")){
                Glide.with(context).load(dataList.get(position).getUserImgUrl()).into(logo);
            }else{
                logo.setImageResource(R.mipmap.default_icon);
            }
        }
    }
}
